import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class j0724_map {
      static  class TreeNode{
        public  TreeNode left;
        public  TreeNode right;
        public int val;

          public TreeNode(int val) {
              this.val = val;
          }
      }
      public static TreeNode pRootOfTree;

     public static TreeNode Creat(){
         TreeNode n1= new TreeNode(2);
         TreeNode n2=new TreeNode(1);
         TreeNode n3=new TreeNode(3);
         n1.left=n2;
         n1.right=n3;
         return n1;
     }
    static List<TreeNode> treeList=new ArrayList<>();

     public  static void inorder(TreeNode pRootOfTree){
         if(pRootOfTree==null){
             return ;
         }
         Convert(pRootOfTree.left);
         treeList.add(pRootOfTree);
         Convert(pRootOfTree.right);

     }

    public static TreeNode Convert(TreeNode pRootOfTree) {
         if(pRootOfTree==null){
             return null;
         }
         inorder(pRootOfTree);
        for (int i = 0; i < treeList.size()-1; i++) {
            treeList.get(i).right=treeList.get(i+1);
            treeList.get(i+1).left=treeList.get(i);
        }
        return treeList.get(0);
    }

    public static void main(String[] args) {
        pRootOfTree=Creat();
        Convert(pRootOfTree);
        System.out.println("");
    }
}
